from langChain import OpenAI,SerpAPIWrapper
from langchain.agents import initialize_agent,Tool
from langchain.agents import AgentType

from dotenv import load_dotenv,find_dotenv

_=load_dotenv(find_dotenv())

llm = OpenAI(template=0)
search = SerpAPIWrapper()

tools = [
  Tool(
    name='Intermediate Answer',
    func =search.run,
    description="useful for when you need to answer questions about current events. provide the name of the person, book, movie, or TV show"
  )
]
"""
适用于层层推理的场景 一问一问
1，吴京的老婆是谁
2，XXX主持过什么节目
"""
self_ask_with_search = initialize_agent(
  tools,llm,agent=AgentType.SELF_ASK_WITH_SEARCH,
  verbose=True)

self_ask_with_search.run("吴京的老婆主持过哪些节目？")